<?php defined('SYSPATH') or die('No direct script access.');

/**
 * Controller for Envy Module
 * The Controller must be called form the command line
 *
 * @package    Envy Module 
 * @author     Howie Weiner
 * @license    http://creativecommons.org/licenses/BSD/
 */

class Envy_Controller extends Controller_Core
{
    public function __construct()
	{
        parent::__construct();

		// prevent script from being run from browser
		if (PHP_SAPI != 'cli')
		{
			Event::run( 'system.404' );
		}
    }

	/**
	 * Default controller action. The method is the env e.g. envy/prod
	 */
	public function __call($method, $args)
	{
		// determine which environment we are setting up
		$env = strtolower($method);
		
		if('index' === $env)
		{
			die ("Please provide an environment name [e.g. dev, test, prod]\n");
		}
					
		echo "Setting up environment for: $env...\n";
		
		// setup environment
		$envy = new Envy_Manager($env);
		$envy->update_files();
	}
} // End Envy_Controller